<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *商品评价管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
//商品评价
$return['stars']=array(
		'1'=>'一星',
		'2'=>'二星',
		'3'=>'三星',
		'4'=>'四星',
		'5'=>'五星',
);
$tabs=array(
	array('op'=>'list','title'=>'评价列表'),
);
if($_RQ['op']=='list'){
	$params=array('type'=>intval($_RQ['type']));
	$params['uniacid']=$_SESSION['uniacid'];
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array();
	$list=pdo_getslice('jy_mapfuwu_ping_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=model('core/core')->member_show($item['mid']);
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'','del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'member','title'=>'会员','type'=>'member'),
			array('name'=>'storeid','title'=>'所属网点','type'=>'select','options'=>'stores'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'ping_types'),
			array('name'=>'content','title'=>'评价内容','type'=>'string'),
			array('name'=>'star','title'=>'星级','type'=>'radio','options'=>'stars'),
			array('name'=>'show','title'=>'是否显示','type'=>'switch','set'=>'set'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'storeid','width'=>10,'title'=>'所属网点','type'=>'select','options'=>'stores'),
			array('type'=>'choose','width'=>13,'title'=>'所属会员','name'=>'mid','action'=>'core/member.get_member/'),
			array('name'=>'createtime','width'=>15,'title'=>'评价时间','type'=>'time_range'),
		)	
	);
	$return['stores']=pdo_getall('jy_mapfuwu_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['ping_types']=$this->ping_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择评价！','error');
	}
	$show=intval($post['show']);
	$this->pdo_update('goods_comments',array('show'=>$show),array('id'=>$id));
	$message=$show?'已显示':'已隐藏';
	exi($message,'error');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_weishop_goods_comments',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}